<?php
/*Ballot class test code */
/*Displays a ballot corresponding to user entered zipcode */

     session_start();
     require_once("GLOBALS.php");
     require_once("../lib/Ballot/Ballot.php");
     include_once("smarty.inc.php");
     include_once("../lib/etc/functions.php");


     //makes it so user can come back here to enter zip+4 and zipcode is remembered
     session_cache_limiter('private_no_expire');


     if(isset($_POST['zip']))
     {
	  $_SESSION['myZip'] = $_POST['zip'];
     }
     if(isset($_POST['plus4']))
     {
	  $_SESSION['plus4'] = $_POST['plus4'];
     }

     try{
	  // Initialize the Ballot object
	  $myBallot = new Ballot($_SESSION['myZip'], $_SESSION['plus4']);


     }catch(NoBallotException $nbe){
	  $smarty->assign('noBallot', 1);

     }catch(NeedPlusFourException $npfe){

	  $smarty->assign('needPlus4', 1);
     }
     $_SESSION['stateAbbr'] = (string)$myBallot->state;

     $_SESSION['state'] = strtolower($STATES[$_SESSION['stateAbbr']]);

// Not necessary to "assign" session variables, accessible directly by Smarty
//      $smarty->assign('zip', $myBallot->zip);
//      $smarty->assign('plus4', $myBallot->plus4);
     $smarty->assign('voteDate', $myBallot->voteDate);
     $smarty->assign('noElect', $myBallot->noElections);
     $smarty->assign('noMeas', $myBallot->noMeasures);
     $smarty->assign('elections', $myBallot->electionData);
     $smarty->assign('measures', $myBallot->measureData);
     $smarty->assign('distOfc', $_SESSION['distOfc']);

     $smarty->display('page2.tpl');
?>